package com.shao.intelligentsnake;

/**
 * 线程安全的参数对象
 *
 * @author shaohuailin
 * @date 2024/4/21
 */
public class GameParams {

    public static final int STATE_EMPTY = 0;
    public static final int STATE_SNAKE = 1;
    public static final int STATE_FOOD  = 2;

    // 单元数量大小
    private int size = 8;
    // 单元单位量
    private int unit = 10;

    // 位置：(单个位置高8位代表x，低8位代表y)
    // 蛇的位置
    private int snakePosition[] = {0};
    // 食物位置
    private int foodPosition = 1;

    // 状态表，记录的是每个位置的状态
    private int[] stateTable = new int[0xFFFF];

    // 游戏结束标记
    private boolean gameOver = false;

    // 是否开启自动模式
    private boolean openAutomatic = false;


    public synchronized int getSize() {
        return size;
    }

    public synchronized void setSize(int size) {
        this.size = size;
    }

    public synchronized int getUnit() {
        return unit;
    }

    public synchronized void setUnit(int unit) {
        this.unit = unit;
    }

    public synchronized int[] getSnakePosition() {
        return snakePosition.clone();
    }

    public synchronized void setSnakePosition(int[] snakePosition) {
        this.snakePosition = snakePosition;
    }

    public synchronized void setSnakePosition(int idx, int value) {
        snakePosition[idx] = value;
    }

    public synchronized int getFoodPosition() {
        return foodPosition;
    }

    public synchronized void setFoodPosition(int foodPosition) {
        this.foodPosition = foodPosition;
    }

    public synchronized int[] getStateTable() {
        return stateTable.clone();
    }

    public synchronized void setStateTable(int[] stateTable) {
        this.stateTable = stateTable;
    }

    public synchronized void setStateTable(int idx, int value) {
        stateTable[idx] = value;
    }

    public synchronized boolean isGameOver() {
        return gameOver;
    }

    public synchronized void setGameOver(boolean gameOver) {
        this.gameOver = gameOver;
    }

    public synchronized boolean isOpenAutomatic() {
        return openAutomatic;
    }

    public synchronized void setOpenAutomatic(boolean openAutomatic) {
        this.openAutomatic = openAutomatic;
    }
}
